/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Connection;

import java.sql.*;

/**
 *
 * @author 2930682
 */
public class DataHandler 
{

  // private static final String _URL = "jdbc:mysql://localhost/gr13_netbooks";
    private static final String _URL = "jdbc:mysql://localhost/dbproject1";
    private static final String _USERNAME = "root";
    private static final String _PASSWORD = "";
    
    private static Connection _connection;
    private static Statement _statement;
    private static ResultSet _resultSet;
    
    public static void createConnection() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException
    {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        _connection = DriverManager.getConnection(_URL, _USERNAME, _PASSWORD);
        
        _statement = _connection.createStatement();
    }
    
    public static void closeConnection() throws SQLException
    {
        _connection.close();
    }
    
    public static ResultSet getProducts() throws SQLException
    {
        runQuery("SELECT * FROM Products");
        
        return _resultSet;
    }
    
    private static void runQuery(String query) throws SQLException
    {
        _resultSet = _statement.executeQuery(query);
    }
    
}
